package learn.advance.bufferstream1;

import java.io.*;

class Demo1BufferOutputStream {
    public static void Test() throws IOException {
        FileOutputStream fos = new FileOutputStream("D:\\workplace\\新建文件夹\\test\\a.txt", true);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        bos.write("把数据写入".getBytes());
        bos.flush();
        bos.close();
    }
}

class Demmo2BufferedInputStream {
    public static void Test() throws IOException {
        FileInputStream fis = new FileInputStream("D:\\workplace\\新建文件夹\\test\\a.txt");
        BufferedInputStream bis = new BufferedInputStream(fis);
        byte[] bytes = new byte[1024];
        int len = 0;
        while ((len = bis.read(bytes)) != -1) {
            System.out.println(new String(bytes, 0, len));
        }
        bis.close();

    }
}

class Demo3BufferedWriter {
    public static void Test() throws IOException {
        BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\workplace\\新建文件夹\\test\\a.txt",true));
        for(int i=0;i<10;i++){
            bw.write("哈哈哈");
            bw.newLine();
        }
        bw.flush();
        bw.close();
    }
}


public class TestBufferStream {
    public static void main(String[] args) throws IOException {
        //Demo1BufferOutputStream.Test();
        //Demmo2BufferedInputStream.Test();
        Demo3BufferedWriter.Test();
    }
}

